package com.weiyin.examination.module;

import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * @author njf
 * @date 2017/10/23
 */

public class BitMapModule implements Parcelable, Cloneable {
    /**
     * bitmap
     */
    private Bitmap bitmap;
    /**
     * 图片大小
     */
    private Rect rect;
    /**
     * 绘制位置
     */
    private MyRectF rectF;
    /**
     * 所在区域
     */
    private Region region;
    /**
     * 多少音符
     */
    private int noteType;
    /**
     * 判断音符是否朝上
     */
    private boolean update;
    /**
     * 是否绘制多余的线
     */
    private boolean drawLine;
    /**
     * 是否休止符
     */
    private boolean repose;
    /**
     * 是否附点
     */
    private boolean spot;
    /**
     * 是否小节线
     */
    private boolean measureLine;

    /**
     * 标记调号
     */
    private int mark;
    /**
     * 是否绘制同音连线
     */
    private boolean homoPhonicConnection;

    /**
     * 是否三连音
     */
    private boolean threeNotes;

    /**
     * 高低音谱号
     */
    private boolean clef;
    /**
     * 音高
     */
    private int pitch;
    private float position;

    protected BitMapModule(Parcel in) {
        bitmap = in.readParcelable(Bitmap.class.getClassLoader());
        rect = in.readParcelable(Rect.class.getClassLoader());
        rectF = in.readParcelable(MyRectF.class.getClassLoader());
        region = in.readParcelable(Region.class.getClassLoader());
        noteType = in.readInt();
        update = in.readByte() != 0;
        drawLine = in.readByte() != 0;
        repose = in.readByte() != 0;
        spot = in.readByte() != 0;
        measureLine = in.readByte() != 0;
        mark = in.readInt();
        homoPhonicConnection = in.readByte() != 0;
        threeNotes = in.readByte() != 0;
        clef = in.readByte() != 0;
        pitch = in.readInt();
        position = in.readFloat();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(bitmap, flags);
        dest.writeParcelable(rect, flags);
        dest.writeParcelable(rectF, flags);
        dest.writeParcelable(region, flags);
        dest.writeInt(noteType);
        dest.writeByte((byte) (update ? 1 : 0));
        dest.writeByte((byte) (drawLine ? 1 : 0));
        dest.writeByte((byte) (repose ? 1 : 0));
        dest.writeByte((byte) (spot ? 1 : 0));
        dest.writeByte((byte) (measureLine ? 1 : 0));
        dest.writeInt(mark);
        dest.writeByte((byte) (homoPhonicConnection ? 1 : 0));
        dest.writeByte((byte) (threeNotes ? 1 : 0));
        dest.writeByte((byte) (clef ? 1 : 0));
        dest.writeInt(pitch);
        dest.writeFloat(position);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<BitMapModule> CREATOR = new Creator<BitMapModule>() {
        @Override
        public BitMapModule createFromParcel(Parcel in) {
            return new BitMapModule(in);
        }

        @Override
        public BitMapModule[] newArray(int size) {
            return new BitMapModule[size];
        }
    };

    @Override
    public BitMapModule clone() {
        BitMapModule bitMapModule = null;
        try {
            bitMapModule = (BitMapModule) super.clone();
            bitMapModule.setRectF(bitMapModule.getRectF().clone());
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return bitMapModule;
    }

    public void setPosition(float position) {
        this.position = position;
    }

    public float getPosition() {
        return position;
    }

    public void setClef(boolean clef) {
        this.clef = clef;
    }

    public boolean isClef() {
        return clef;
    }


    public void setPitch(int pitch) {
        this.pitch = pitch;
    }

    public int getPitch() {
        return pitch;
    }

    public void setThreeNotes(boolean threeNotes) {
        this.threeNotes = threeNotes;
    }

    public boolean isThreeNotes() {
        return threeNotes;
    }

    public void setHomoPhonicConnection(boolean homoPhonicConnection) {
        this.homoPhonicConnection = homoPhonicConnection;
    }

    public boolean isHomoPhonicConnection() {
        return homoPhonicConnection;
    }

    public void setMark(int mark) {
        this.mark = mark;
    }

    public int getMark() {
        return mark;
    }

    public void setMeasureLine(boolean measureLine) {
        this.measureLine = measureLine;
    }

    public boolean isMeasureLine() {
        return measureLine;
    }

    public BitMapModule() {
        this.spot = false;
    }

    public boolean isSpot() {
        return spot;
    }

    public void setSpot(boolean spot) {
        this.spot = spot;
    }

    public void setRepose(boolean repose) {
        this.repose = repose;
    }

    public boolean isRepose() {
        return repose;
    }

    public boolean isDrawLine() {
        return drawLine;
    }

    public void setDrawLine(boolean drawLine) {
        this.drawLine = drawLine;
    }

    public boolean isUpdate() {
        return update;
    }

    public void setUpdate(boolean update) {
        this.update = update;
    }

    public int getNoteType() {
        return noteType;
    }

    public void setNoteType(int noteType) {
        this.noteType = noteType;
    }

    public void setRegion(Region region) {
        this.region = region;
    }

    public Region getRegion() {
        return region;
    }

    public Bitmap getBitmap() {
        return bitmap;
    }

    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    public Rect getRect() {
        return rect;
    }

    public void setRect(Rect rect) {
        this.rect = rect;
    }

    public MyRectF getRectF() {
        return rectF;
    }

    public void setRectF(MyRectF rectF) {
        this.rectF = rectF;
    }
}
